package cn.schoolwow.flow.monitor.module.business.scheduleJob.cases.service;

import cn.schoolwow.flow.monitor.domain.FlowMonitorOption;
import cn.schoolwow.flow.monitor.domain.ScheduleJobFlow;
import cn.schoolwow.flow.monitor.entity.FlowLog;
import cn.schoolwow.flow.monitor.entity.ScheduleJobLog;
import cn.schoolwow.flow.monitor.entity.TestCaseLog;
import cn.schoolwow.flow.monitor.module.business.scheduleJob.cases.flow.DatabaseLogCleanFlow;
import cn.schoolwow.quickflow.domain.FlowContext;
import org.springframework.context.ApplicationContext;

public class CleanFlowLogScheduleJobFlow implements ScheduleJobFlow {
    @Override
    public String cron() {
        return "0 0 0/1 * * *";
    }

    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        ApplicationContext applicationContext = flowContext.checkInstanceData(ApplicationContext.class);
        FlowMonitorOption flowMonitorOption = applicationContext.getBean(FlowMonitorOption.class);
        String[] tableNames = new String[]{
                flowMonitorOption.dao.getEntity(FlowLog.class).tableName,
                flowMonitorOption.dao.getEntity(ScheduleJobLog.class).tableName,
                flowMonitorOption.dao.getEntity(TestCaseLog.class).tableName
        };

        flowContext.startFlow(new DatabaseLogCleanFlow())
                .putData("tableNames", tableNames)
                .putData("remainDay", 7)
                .execute();
    }

    @Override
    public String name() {
        return "定时清理流程日志";
    }
}
